<?php

namespace App\Models\Applet\Order;

class ShopOrderGoodsModel extends BaseOrderModel
{
    protected $table = 'shop_order_goods';

    /**
     * 根据订单ids获取数据
     * @param array $orderIds
     * @param array $fields
     * @return array
     */
    public function getItemsByOrderIds(array $orderIds, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
                    ->whereIn('order_id', $orderIds)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }

    /**
     * 根据订单id和商品id获取数据
     * @param int $orderId
     * @param int $goodsId
     * @param array $fields
     * @return array
     */
    public function getItemByOrderIdAndGoodsId(int $orderId, int $goodsId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('order_id', $orderId)
                       ->where('goods_id', $goodsId)
                       ->where('deleted', self::DELETED_NO)
                       ->first();
        return $result ? $result->toArray() : [];
    }

}
